import moment, { Moment } from 'moment';
const WEEK = [ '一', '二', '三', '四', '五', '六','日']
export interface WeekDate {
  date: string;
  week: string;
}

/**
 * 获取给定日期所在周的周一至周日的日期数组
 * @param date 输入的日期
 * @returns 周一至周日的日期数组
 */
export function getWeekDates(date: string | Date | Moment): Array<WeekDate> {
  // 将输入的日期转换为 Moment 对象
  const mDate = moment(date);

  // 获取当前日期是周几，0:周日, 1:周一, ..., 6:周六
  // const dayOfWeek = mDate.day();

  // 计算当前日期距离周一的天数差
  const startOfWeek = mDate.clone().startOf('week'); // 获取本周的周一
  const weekDates: Array<WeekDate> = [];

  // 获取当前周从周一到周日的日期
  for (let i = 0; i < 7; i++) {
    weekDates.push({
      date: startOfWeek.clone().add(i, 'days').format('YYYY-MM-DD'),
      week: WEEK[i]
    });
  }

  return weekDates;
}

export function getPreviousWeekDate(date: string): string {
  return moment(date).subtract(7, 'days').format('YYYY-MM-DD');
}

export function getNextWeekDate(date: string): string {
  return moment(date).add(7, 'days').format('YYYY-MM-DD');
}
